﻿//https://leetcode.cn/problems/longest-substring-without-repeating-characters/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    int lengthOfLongestSubstring(string s) {

        int n = s.size(), len = 0;
        int left = 0, right = 0;
        int hash[128] = { 0 };
        while (right < n)
        {
            //进窗口
            hash[s[right]]++;
            //判断
            while (hash[s[right]] > 1)
            {
                //出窗口
                hash[s[left++]]--;

            }
            //更新结果
            len = max(len, right - left + 1);
            //继续进窗口
            right++;

        }

        return len;

    }
};